package com.zwz.controller;


import com.zwz.entity.Trademark;
import com.zwz.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/trademarks")
public class TrademarkController {

    @Autowired
    private TrademarkService trademarkService;

    @PostMapping
    public ResponseEntity<?> create(@RequestBody Trademark trademark) {
        try {
//            trademarkService.createTrademark(trademark);
            ResponseEntity.ok("商标创建成功");
        } catch (IllegalArgumentException e) {
            return ResponseEntity.ok(e.getMessage());
        }
        return null;
    }

    @GetMapping("/{id}")
    public ResponseEntity<Trademark> getById(@PathVariable String id) {
        return ResponseEntity.ok(trademarkService.getById(id));
    }

    @GetMapping("/company/{companyName}")
    public ResponseEntity<List<Trademark>> getByCompany(
            @PathVariable String companyName) {
        return ResponseEntity.ok(trademarkService.getByCompany(companyName));
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<?> delete(@PathVariable String id) {
        trademarkService.deleteTrademark(id);
        return ResponseEntity.ok("删除成功");
    }
}